import Bullet from "./bullet.js"

class WaveBullet extends Bullet {
    constructor(weapon, start, end, config, index) {
        super(weapon, start, end, config, index);
        this.radius = 0;
        this.frame_index = index;
    }

    draw() {
        let ctx = this.game.stage_canvas_ctx;
        let start = this.start_pos;

        let alpha = 1.01 - (this.radius / this.config.fire_range);
        let style1 = "rgba(0, 255, 0, " + alpha + ")";
        let style2 = "rgba(0, 0, 255, " + alpha + ")";
        ctx.strokeStyle = this.frame_index % 2 === 0 ? style1 : style2;
        let line_width = this.radius / 10;
        ctx.lineWidth = line_width;
        ctx.setLineDash([line_width * 2, line_width * 2]);
        ctx.lineCap = "round";

        ctx.beginPath();
        ctx.arc(start[0], start[1], this.radius, 0, Math.PI * 2, true);
        ctx.stroke();

        ctx.setLineDash([]);
    };

    is_end() {
        return this.radius >= this.config.fire_range;
    };

    move_on() {
        if (this.radius < this.config.fire_range) {
            this.radius += this.config.bullet_speed;
        }
    };
}

export default WaveBullet;